<style lang="less">
@import '~$common/funs.less';
.cps-center-tip {
  background-color: #ffffff;
  // text-align: center;
  border-radius: 20px;
  overflow: hidden;
  transition: transform 0.3s ease-out, opacity 0.15s ease-out;
  margin: 0 94px;
  position: relative;
  .close {
    position: absolute;
    top: 30px;
    right: 30px;

    color: @font-hint;
  }
  .detail {
    word-break: break-all;
    // white-space: pre-wrap;
    padding: 30px;
    max-height: 780px;
    overflow: auto;
    font-size: 26px;
    line-height: 40px;
    overscroll-behavior: contain;
    box-sizing: border-box;
    background-color: #ffffff;
  }
}
</style>

<template>
  <simple-mask v-bind="$attrs" type="center" v-if="this.moreLevels" v-show="showCurrentMask">
    <div class="cps-center-tip iphonex-fixed-bottom">
      <div class="close" @click="closePop">
        <icon-close></icon-close>
      </div>

      <div class="detail" :style="contextStyle" :class="contextClass" ref="detail">
        <slot></slot>
      </div>
    </div>
  </simple-mask>
  <simple-mask-two-level v-bind="$attrs" type="center" v-else v-show="showCurrentMask">
    <div class="cps-center-tip iphonex-fixed-bottom">
      <div class="close" @click="closePop">
        <icon-close></icon-close>
      </div>

      <div class="detail" :style="contextStyle" :class="contextClass" ref="detail">
        <slot></slot>
      </div>
    </div>
  </simple-mask-two-level>
</template>

<script>
export default {
  name: 'cps-center-tip',
  components: {
    iconClose: require('../../svg/close.vue').default,
    simpleMaskTwoLevel: require('../mask/index_two_level').default
  },
  props: {
    // 标题
    title: {
      type: String,
      default: ''
    },
    moreLevels: {
      type: Boolean,
      default: false
    },
    leonisId: {
      type: String,
      default: ''
    },
    contextClass: {
      type: String,
      default: ''
    },
    contextHeight: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      html: '',
      showCurrentMask: true
    }
  },
  computed: {
    contextStyle() {
      let style = {}
      if (this.cVisable) {
        style.maxHeight = (window.innerHeight * 0.75 || 780) + 'px'
      }
      if (this.contextHeight) {
        style.height = this.contextHeight + 'px'
      }
      return style
    }
  },
  inject: ['closePopMask'],
  watch: {
    //  ** 子组件这里监听showMask
    '$attrs.showMask'(nv, ov) {
      if (nv != ov) {
        this.$nextTick(() => {
          try {
            this.$refs.detail.scrollTop = 0
          } catch (e) {}
        })
      }
    }
  },
  mounted() {
    if (this.leonisId) {
      try {
        this.$model.leonis.dispatch(this.leonisId, res => {
          this.html = res
        })
      } catch (e) {}
    }
  },
  methods: {
    closePop() {
      this.closePopMask()
      this.showCurrentMask = false
    }
  }
}
</script>